package com.ruoyi.business.service.fission.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.fission.TbWecomChatGroupFissionScene;
import com.ruoyi.business.domain.vo.business.TbUserDetailVO;
import com.ruoyi.business.domain.vo.fission.admin.FissionActivitySysDetailVO;
import com.ruoyi.business.domain.vo.fission.api.SceneInfoVO;
import com.ruoyi.business.mapper.fission.TbWecomChatGroupFissionSceneMapper;
import com.ruoyi.business.service.fission.ITbWecomChatGroupFissionSceneService;
import com.ruoyi.business.service.fission.ITbWecomChatGroupFissionService;
import com.ruoyi.business.service.koc.ITbUserService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * <p>
 * 群裂变场景表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-xx-xx
 */
@Service
public class TbWecomChatGroupFissionSceneServiceImpl extends ServiceImpl<TbWecomChatGroupFissionSceneMapper, TbWecomChatGroupFissionScene> implements ITbWecomChatGroupFissionSceneService {

    @Resource
    private ITbUserService tbUserService;

    @Resource
    @Lazy
    private ITbWecomChatGroupFissionService tbWecomChatGroupFissionService;

    @Override
    public SceneInfoVO queryByScene(Long userId, String scene) {
        TbWecomChatGroupFissionScene tbWecomChatGroupFissionScene = this.getById(scene);
        // 群裂变活动id
        Long fissionId = tbWecomChatGroupFissionScene.getFissionId();
        // 分享人id
        Long shareUserId = tbWecomChatGroupFissionScene.getUserId();
        FissionActivitySysDetailVO fissionActivitySysDetailVO = tbWecomChatGroupFissionService.sysSelectDetail(fissionId);
        SceneInfoVO sceneInfoVO = SceneInfoVO.builder().sceneType(tbWecomChatGroupFissionScene.getType()).fissionActivitySysDetailVO(fissionActivitySysDetailVO).build();
        if (ObjectUtil.isNotEmpty(shareUserId)) {
            TbUserDetailVO tbUserDetailVO = tbUserService.getUserDetailById(shareUserId);
            if (ObjectUtil.isNotEmpty(tbUserDetailVO)) {
                sceneInfoVO.setTbUserDetailVO(tbUserDetailVO);
            }
        }
        return sceneInfoVO;
    }

}
